﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.Globalization;
using BlobTowerDefense.Game_Entities;
using BlobTowerDefense.Managers;

using System.Collections.Generic;

namespace BlobTowerDefense.Tools
{
    public class Saver
    {        
        public static void Save_LeftHanded(bool isLeftHanded)
        {
            if (App.AppSettings.Contains("LeftHanded"))
            {
                App.AppSettings["LeftHanded"] = isLeftHanded;
            }
            else
            {
                App.AppSettings.Add("LeftHanded", isLeftHanded);
            }
        }

        public static void Save_Sensitivity(double sensitivity)
        {
            if (App.AppSettings.Contains("Sensitivity"))
            {
                App.AppSettings["Sensitivity"] = sensitivity;
            }
            else
            {
                App.AppSettings.Add("Sensitivity", sensitivity);
            }
        }

        public static void Save_MasterVolume_Current(short masterVolume)
        {
            if (App.AppSettings.Contains("MasterVolume_Current"))
            {
                App.AppSettings["MasterVolume_Current"] = masterVolume;
            }
            else
            {
                App.AppSettings.Add("MasterVolume_Current", masterVolume);
            }
        }

        public static void Save_MusicVolume_Current(short musicVolume)
        {
            if (App.AppSettings.Contains("MusicVolume_Current"))
            {
                App.AppSettings["MusicVolume_Current"] = musicVolume;
            }
            else
            {
                App.AppSettings.Add("MusicVolume_Current", musicVolume);
            }
        }

        public static void Save_SoundsVolume_Current(short soundsVolume)
        {
            if (App.AppSettings.Contains("SoundsVolume_Current"))
            {
                App.AppSettings["SoundsVolume_Current"] = soundsVolume;
            }
            else
            {
                App.AppSettings.Add("SoundsVolume_Current", soundsVolume);
            }
        }

        public static void Save_MasterVolume_Previous(short masterVolume)
        {
            if (App.AppSettings.Contains("MasterVolume_Previous"))
            {
                App.AppSettings["MasterVolume_Previous"] = masterVolume;
            }
            else
            {
                App.AppSettings.Add("MasterVolume_Previous", masterVolume);
            }
        }

        public static void Save_MusicVolume_Previous(short musicVolume)
        {
            if (App.AppSettings.Contains("MusicVolume_Previous"))
            {
                App.AppSettings["MusicVolume_Previous"] = musicVolume;
            }
            else
            {
                App.AppSettings.Add("MusicVolume_Previous", musicVolume);
            }
        }

        public static void Save_SoundsVolume_Previous(short soundsVolume)
        {
            if (App.AppSettings.Contains("SoundsVolume_Previous"))
            {
                App.AppSettings["SoundsVolume_Previous"] = soundsVolume;
            }
            else
            {
                App.AppSettings.Add("SoundsVolume_Previous", soundsVolume);
            }
        }

        public static void Save_Culture(CultureInfo culture)
        {
            if (App.AppSettings.Contains("Culture"))
            {
                App.AppSettings["Culture"] = culture;
            }
            else
            {
                App.AppSettings.Add("Culture", culture);
            }
        }

        public static void Save_HighScore(string name, int score)
        {
            string[] previous_names = Loader.Load_HighScore_Names();
            int[] previous_scores = Loader.Load_HighScore_Scores();
            

            string[] current_names;
            int[] current_scores;

            if (previous_names != null && previous_scores != null)
            {
                current_names = new string[previous_names.Length + 1];
                current_scores = new int[previous_scores.Length + 1];

                for (int i = 0; i < previous_names.Length; i++)
                {
                    if (previous_names[i] == name && previous_scores[i] == score)
                    {
                        return;
                    }
                    current_names[i] = previous_names[i];
                    current_scores[i] = previous_scores[i];
                }
            }
            else
            {
                current_names = new string[1];
                current_scores = new int[1];
            }
            current_names[current_names.Length - 1] = name;
            current_scores[current_scores.Length - 1] = score;

            if (App.AppSettings.Contains("HighScore_Names"))
            {
                App.AppSettings["HighScore_Names"] = current_names;
            }
            else
            {
                App.AppSettings.Add("HighScore_Names", current_names);
            }

            if (App.AppSettings.Contains("HighScore_Scores"))
            {
                App.AppSettings["HighScore_Scores"] = current_scores;
            }
            else
            {
                App.AppSettings.Add("HighScore_Scores", current_scores);
            }
        }

        public static void Save_NickName(string nickName)
        {
            if (App.AppSettings.Contains("NickName"))
            {
                App.AppSettings["NickName"] = nickName;
            }
            else
            {
                App.AppSettings.Add("NickName", nickName);
            }
        }

        public static void Save_GamePage(GamePage gamePage)
        {
            if (App.AppSettings.Contains("GamePage_Saved"))
            {
                App.AppSettings["GamePage_Saved"] = gamePage;
            }
            else
            {
                App.AppSettings.Add("GamePage_Saved", gamePage);
            }
        }

        public static void Save_WaveType(WAVETYPE waveType)
        {
            if (App.AppSettings.Contains("SavedWaveType"))
            {
                App.AppSettings["SavedWaveType"] = waveType;
            }
            else
            {
                App.AppSettings.Add("SavedWaveType", waveType);
            }
        }

        public static void Save_Difficulty(DIFFICULTY difficulty)
        {
            if (App.AppSettings.Contains("SavedDifficulty"))
            {
                App.AppSettings["SavedDifficulty"] = difficulty;
            }
            else
            {
                App.AppSettings.Add("SavedDifficulty", difficulty);
            }
        }

        public static void Save_PlayerHP(int playerHP)
        {
            if (App.AppSettings.Contains("SavedPlayerHP"))
            {
                App.AppSettings["SavedPlayerHP"] = playerHP;
            }
            else
            {
                App.AppSettings.Add("SavedPlayerHP", playerHP);
            }
        }

        public static void Save_PlayerMoney(int playerMoney)
        {
            if (App.AppSettings.Contains("SavedPlayerMoney"))
            {
                App.AppSettings["SavedPlayerMoney"] = playerMoney;
            }
            else
            {
                App.AppSettings.Add("SavedPlayerMoney", playerMoney);
            }
        }

        public static void Save_Towers(List<Tower> towers)
        {
            if (App.AppSettings.Contains("SavedTowers"))
            {
                App.AppSettings["SavedTowers"] = towers;
            }
            else
            {
                App.AppSettings.Add("SavedTowers", towers);
            }
        }
    }
}
